<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    距离2020年高考，还有<span></span>天<span></span>小时<span></span>分钟<span></span>秒
    <script>
        //1
        var date0 = new Date();
        var t = 10 * 24 * 60 * 60 * 1000 + date0.getTime();
        console.log('10天后是' + new Date(t).toLocaleString());
        //2
        var date5 = new Date('2019-02-25');
        var t1 = 10 * 24 * 60 * 60 * 1000 + date5.getTime();
        console.log('2019年2月25日10天后是' + new Date(t1).toLocaleString());
        //3
        var a = new Date('2020-07-07');
        var b = new Date();
        var day0 = Math.floor((a.getTime() - b.getTime()) / 1000 / 60 / 60 / 24);
        console.log('距离高考还有' + day0 + '天');
        //4
        var date = new Date('2020-07-07');
        var spans = document.getElementsByTagName('span');
        var dateTime = date.getTime(),
            dateNow,
            dateNowTime,
            day,
            hour,
            minute,
            second;
        setInterval(function() {
            dateNow = new Date();
            dateNowTime = dateNow.getTime();
            day = Math.floor((dateTime - dateNowTime) / 1000 / 60 / 60 / 24);
            hour = Math.floor((dateTime - dateNowTime) / 1000 / 60 / 60) - day * 24;
            minute = Math.floor((dateTime - dateNowTime) / 1000 / 60) - day * 24 * 60 - hour * 60;
            second = Math.floor((dateTime - dateNowTime) / 1000) - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60;
            spans[0].innerHTML = day;
            spans[1].innerHTML = hour;
            spans[2].innerHTML = minute;
            spans[3].innerHTML = second;
        }, 1000);
    </script>
</body>

</html>